#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
void _mas(int* a, int* tmp, int left, int right)
{
	if (left >= right)
		return;
	int mid = (left + right) / 2;
	_mas(a, tmp, left, mid);
	_mas(a, tmp, mid + 1, right);
	int i = left;
	int begin1 = left;
	int end1 = mid;
	int begin2 = mid + 1;
	int end2 = right;
	while (begin1<=end1&&begin2<=end2)
	{
		if (a[begin1] < a[begin2])
		{
			tmp[i++] = a[begin1++];
		}
		else
		{
			tmp[i++] = a[begin2++];
		}
	}
	while (begin1 <= end1)
	{
		tmp[i++] = a[begin1++];
	}
	while (begin2 <= end2)
	{
		tmp[i++] = a[begin2++];
	}
	memcpy(a + left, tmp + left, (right-left+1) * sizeof(int));
}
void guibingpaixu(int* a,int n)
{
	int* tmp = (int*)malloc(sizeof(int) * n);
	if (tmp == NULL)
	{
		perror("malloc");
	}
	int left = 0;
	int right = n - 1;
	_mas(a, tmp, left, right);
	free(tmp);
}
int main()
{
	int a[] = { 364,57,568,76,86,9,879,8099,3,6,72,6865,867,98,8679,8790,57,978,98,653,7,265,134,65,766598467,9476894876,9 };

	guibingpaixu(a,sizeof(a)/sizeof(a[0]));
	for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
	{
		printf("%d ", a[i]);
	}

	return 0;
}